package queue;

import java.util.LinkedList;

public class MessageQueue {
    private LinkedList<Message> queue;

    public MessageQueue() {
        queue = new LinkedList<>();
    }

    public synchronized void addMessage(Message message) {
        queue.add(message);
        notifyAll();
    }

    public synchronized Message getMessage() throws InterruptedException {
        while (queue.isEmpty()) {
            wait();
        }
        return queue.remove();
    }
}
